package top.shmly.universal.base.validator;


import top.shmly.universal.base.validator.utils.IdCardUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;


public class IdCardValidator implements ConstraintValidator<IdCard, String> {

    @Override
    public void initialize(IdCard idCard) {
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        if (value == null || "".equals(value)) {
            return false;
        }
        int s = 15;
        if (value.length() == s) {
            return IdCardUtils.validate15IdCard(value);
        }
        int s1 = 18;
        if (value.length() == s1) {
            return IdCardUtils.validate18IdCard(value);
        }
        return false;
    }

}
